from base.base_other_page import BaseObject, BaseOperate
from utils import close_all_windows


class HomePage(BaseObject):
    """
    家园沙盘
    """

    def __init__(self):
        super().__init__()
        # 弹窗关闭X按钮
        self.close_btn = "btnClose"
        self.close_other_btn = "CloseBtn"
        # GM
        self.gm_btn = "GMIcon"
        # 任务按钮
        self.task_btn = "BtnTask", "Head"
        # 势力按钮
        self.forces_btn = "势力"

    # 定位每日任务按钮
    def find_task_btn(self):
        return self.get_element_judge_parent(self.task_btn)

    # 定位弹窗关闭X按钮（第一种）
    def find_close_btn(self):
        return self.get_element_by_parent(self.close_btn)

    # 定位第二种弹窗关闭按钮（第二种）
    def find_close_other_btn(self):
        return self.get_element_by_parent(self.close_other_btn)

    # 定位势力按钮
    def find_forces_btn(self):
        return self.get_element_by_text(self.forces_btn)

    # GM按钮
    def find_gm_btn(self):
        return self.get_element_by_parent(self.gm_btn)


class HomeOperate(BaseOperate):
    def __init__(self):
        self.hp = HomePage()

    def click_task_btn(self):
        self.hp.find_task_btn().click()

    def click_all_close_btn1(self):
        close_all_windows(self.hp.find_close_btn())

    def click_all_close_btn2(self):
        close_all_windows(self.hp.find_close_other_btn())

    def click_forces_btn(self):
        self.hp.find_forces_btn().click()

    def click_gm_btn(self):
        self.hp.find_gm_btn().click()


class HomeBusiness:
    def __init__(self):
        self.ho = HomeOperate()

    # 关闭弹窗，两种按钮
    def close_all(self):
        self.ho.click_all_close_btn1()
        self.ho.click_all_close_btn2()

    # 任务
    def open_task_list(self):
        self.ho.click_task_btn()

    # 势力
    def open_forces_page(self):
        self.ho.click_forces_btn()

    # GM页面
    def open_gm_page(self):
        self.ho.click_gm_btn()
